package com.bw.user.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.bw.user.entity.PageResult;
import com.bw.user.entity.Result;
import com.bw.user.pojo.TUser;
import com.bw.user.service.UserService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



@RestController
@RequestMapping("user")
public class UserController {
    @Reference
    UserService userService;

    /**
     * 列表
     * @param page
     * @param rows
     * @param tUser
     * @return
     */
    @RequestMapping("findPage")
    public PageResult findPage(int page, int rows, @RequestBody TUser tUser){
        return userService.findPage(page,rows,tUser);
    }

    /**
     * 添加
     * @param tUser
     * @return
     */
    @RequestMapping("save")
    public Result save(@RequestBody TUser tUser){
        try{
            userService.save(tUser);
            return new Result(true,"");
        }catch (Exception e){
            return new Result(false,"服务器出现异常！");
        }
    }

    /**
     * 修改回显
     * @param uid
     * @return
     */
    @RequestMapping("edit")
    public TUser edit(int uid){
       return userService.edit(uid);
    }

    /**
     * 修改
     * @param tUser
     * @return
     */
    @RequestMapping("update")
    public Result update(@RequestBody TUser tUser){
        try{
            userService.update(tUser);
            return new Result(true,"");
        }catch (Exception e){
            return new Result(false,"服务器出现异常！");
        }
    }
    @RequestMapping("dele")
    public Result dele(int[] ids){
        try{
            userService.dele(ids);
            return new Result(true,"");
        }catch (Exception e){
            return new Result(false,"服务器出现异常！");
        }
    }

}
